package com.yq.design.iterator;

import java.util.Iterator;

/**
 * @ClassName ComputerIterator
 * @Description computerIterator系实现iterator，重写遍历系计系的数组，
 * @Author yaoqiang
 * @Date 2021/8/24 11:38
 * @Version 1.0
 */
public class ComputerIterator implements Iterator {
    Department[] departments;
    int position=0;

    @Override
    public boolean hasNext() {
        if (position>=departments.length||departments[position]==null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Object next() {
        Department department=departments[position];
        position+=1;
        return  department;
    }

    public ComputerIterator(Department[] departments) {
        this.departments = departments;
    }

}
